package com.kinyx.framework.security;

import java.util.Date;
import java.util.Properties;

import com.kinyx.framework.annotation.assist.ReturnNotNull;
import com.kinyx.framework.annotation.assist.Tester;
import com.kinyx.framework.business.KHexUtils;
import com.kinyx.framework.file.KPropertiesReader;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * OTP编码工具类
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Tester("com.kinyx.framework.security.KOTP_Tester_")
public final class KOTP {

	/** 配置属性 */
	private static final Properties PROPERTIES = KPropertiesReader.read("configs-otp.properties");

	/** 秘钥 */
	private static final String key = KPropertiesReader.getStringValue(PROPERTIES, "otp.key", "Kinyx");
	/** 间隔时间（毫秒） */
	private static final Long timeout = KPropertiesReader.getLongValue(PROPERTIES, "otp.timeout", 600000L);

	/**
	 * 编码
	 * @return 编码
	 */
	@ReturnNotNull
	public static String encrypt() {
		return KMD5.encrypt(KHexUtils.long2hex(new Date().getTime() / timeout), key, "UTF-8");
	}

}
